package me.firstapp.manage.product;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import me.firstapp.common.exception.ServiceException;
import me.firstapp.common.exception.StatusHouse;
import me.firstapp.common.json.SingleObject;
import me.firstapp.common.utils.Page;
import me.firstapp.common.utils.ResponseUtils;
import me.firstapp.common.utils.StrUtils;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.manage.utils.BizData4Page;
import me.firstapp.module.weixin.product.Product;
import me.firstapp.module.weixin.product.ProductCategory;
import me.firstapp.module.weixin.product.ProductSku;
import me.firstapp.module.weixin.product.RebateGrid;
import me.firstapp.module.weixin.product.Supplier;
import me.firstapp.service.weixin.product.ProductCategoryService;
import me.firstapp.service.weixin.product.ProductService;
import me.firstapp.service.weixin.product.ProductSkuService;
import me.firstapp.service.weixin.product.RebateGridService;
import me.firstapp.service.weixin.product.SupplierService;

@Controller
@RequestMapping(value = "/productManage")
public class ProductManageAct extends BaseManage {

	@Autowired
	private ProductCategoryService productCategoryService;

	@Autowired
	private ProductService productService;

	@Autowired
	private SupplierService supplierService;

	@Autowired
	private ProductSkuService productSkuService;

	@Autowired
	private RebateGridService rebateGridService;

	@ResponseBody
	@RequestMapping(value = "/findProductCategoryPage.do", method = RequestMethod.POST)
	public void findProductCategoryPage(@RequestParam Map<String, Object> conditions, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<ProductCategory> productCategoryPage = productCategoryService.findProductCategoryPage(pageNo,
						iDisplayLength, searchParams, mDataProp, sSortDir_0);

				BizData4Page<ProductCategory> bizData4Page = new BizData4Page<ProductCategory>();
				bizData4Page.setUserdata(conditions);
				if (productCategoryPage != null) {
					bizData4Page.setPage(productCategoryPage.getPageNo());
					bizData4Page.setPagesize(productCategoryPage.getPageSize());
					bizData4Page.setRecords(productCategoryPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<ProductCategory>(productCategoryPage.getEntities()));
					bizData4Page.setTotal(productCategoryPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/addProductCategory.do", method = RequestMethod.POST)
	public void addProductCategory(String name, String imageUrl, String description, Integer sort, String tag,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			productCategoryService.executeAdd(name, imageUrl, description, sort, tag);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateProductCategory.do", method = RequestMethod.POST)
	public void updateProductCategory(Long categoryId, String name, String imageUrl, String description, Integer sort,
			Integer status, String tag, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			productCategoryService.executeUpdate(categoryId, name, imageUrl, description, sort, status, tag);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findProductPage.do", method = RequestMethod.POST)
	public void findProductPage(@RequestParam Map<String, Object> conditions, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<Product> productPage = productService.findProductPage(pageNo, iDisplayLength, searchParams,
						mDataProp, sSortDir_0);

				BizData4Page<Product> bizData4Page = new BizData4Page<Product>();
				bizData4Page.setUserdata(conditions);
				if (productPage != null) {
					bizData4Page.setPage(productPage.getPageNo());
					bizData4Page.setPagesize(productPage.getPageSize());
					bizData4Page.setRecords(productPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<Product>(productPage.getEntities()));
					bizData4Page.setTotal(productPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/addProduct.do", method = RequestMethod.POST)
	public void addProduct(Long productCategoryId, Long supplierId, String name, String imgUrl, String detailUrl,
			String outUrl, String unit, BigDecimal cost, BigDecimal startFreight, BigDecimal unitFreight,
			Integer limitUnit, BigDecimal fansPrice, BigDecimal baseVipPrice, BigDecimal highVipPrice,
			BigDecimal chiefBaseVipJinBi, BigDecimal chiefHighVipJinBi, BigDecimal chiefBaseVipPoint,
			BigDecimal chiefHighVipPoint, String description, String remark, Integer tuiJian,
			BigDecimal fansBuyGiveOtherJb, BigDecimal baseVipBuyGiveOtherJb, BigDecimal highVipBuyGiveOtherJb,
			Integer sort, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			Product product = productService.executeAdd(productCategoryId, supplierId, name, imgUrl, detailUrl, outUrl,
					unit, cost, startFreight, unitFreight, limitUnit, fansPrice, baseVipPrice, highVipPrice,
					chiefBaseVipJinBi, chiefHighVipJinBi, chiefBaseVipPoint, chiefHighVipPoint, description, remark,
					tuiJian, fansBuyGiveOtherJb, baseVipBuyGiveOtherJb, highVipBuyGiveOtherJb, sort);
			rebateGridService.executeAddUpdate(product);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateProduct.do", method = RequestMethod.POST)
	public void updateProduct(Long id, Long productCategoryId, Long supplierId, String name, String imgUrl,
			String detailUrl, String outUrl, String unit, BigDecimal cost, BigDecimal startFreight,
			BigDecimal unitFreight, Integer limitUnit, BigDecimal fansPrice, BigDecimal baseVipPrice,
			BigDecimal highVipPrice, BigDecimal chiefBaseVipJinBi, BigDecimal chiefHighVipJinBi,
			BigDecimal chiefBaseVipPoint, BigDecimal chiefHighVipPoint, String description, String remark,
			Integer status, Integer tuiJian, BigDecimal fansBuyGiveOtherJb, BigDecimal baseVipBuyGiveOtherJb,
			BigDecimal highVipBuyGiveOtherJb, Integer sort, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			Product product = productService.executeUpdate(id, productCategoryId, supplierId, name, imgUrl, detailUrl,
					outUrl, unit, cost, startFreight, unitFreight, limitUnit, fansPrice, baseVipPrice, highVipPrice,
					chiefBaseVipJinBi, chiefHighVipJinBi, chiefBaseVipPoint, chiefHighVipPoint, description, remark,
					status, tuiJian, fansBuyGiveOtherJb, baseVipBuyGiveOtherJb, highVipBuyGiveOtherJb, sort);
			rebateGridService.executeAddUpdate(product);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findSupplierPage.do", method = RequestMethod.POST)
	public void findSupplierPage(@RequestParam Map<String, Object> conditions, Long id, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<Supplier> supplierPage = supplierService.findSupplierPage(pageNo, iDisplayLength, searchParams,
						mDataProp, sSortDir_0, id);

				BizData4Page<Supplier> bizData4Page = new BizData4Page<Supplier>();
				bizData4Page.setUserdata(conditions);
				if (supplierPage != null) {
					bizData4Page.setPage(supplierPage.getPageNo());
					bizData4Page.setPagesize(supplierPage.getPageSize());
					bizData4Page.setRecords(supplierPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<Supplier>(supplierPage.getEntities()));
					bizData4Page.setTotal(supplierPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/addSupplier.do", method = RequestMethod.POST)
	public void addSupplier(String sysName, String name, String contacts, String shopUrl, String idCard, String qq,
			String ww, String weixin, String telPhone, String mobile, String email, String address, String remark,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			supplierService.executeAdd(sysName, name, contacts, shopUrl, idCard, qq, ww, weixin, telPhone, mobile,
					email, address, remark);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateSupplier.do", method = RequestMethod.POST)
	public void updateSupplier(Long id, String sysName, String name, String contacts, String shopUrl, String idCard,
			String qq, String ww, String weixin, String telPhone, String mobile, String email, String address,
			String remark, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			supplierService.executeUpdate(id, sysName, name, contacts, shopUrl, idCard, qq, ww, weixin, telPhone,
					mobile, email, address, remark);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findProductSkuPage.do", method = RequestMethod.POST)
	public void findProductSkuPage(@RequestParam Map<String, Object> conditions, Long productId,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<ProductSku> productSkuPage = productSkuService.findProductSkuPage(pageNo, iDisplayLength,
						searchParams, mDataProp, sSortDir_0, productId);

				BizData4Page<ProductSku> bizData4Page = new BizData4Page<ProductSku>();
				bizData4Page.setUserdata(conditions);
				if (productSkuPage != null) {
					bizData4Page.setPage(productSkuPage.getPageNo());
					bizData4Page.setPagesize(productSkuPage.getPageSize());
					bizData4Page.setRecords(productSkuPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<ProductSku>(productSkuPage.getEntities()));
					bizData4Page.setTotal(productSkuPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/addProductSku.do", method = RequestMethod.POST)
	public void addProductSku(Long productId, String skuName, Integer isDefault, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			productSkuService.executeAdd(productId, skuName, isDefault);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateProductSku.do", method = RequestMethod.POST)
	public void updateProductSku(Long id, String skuName, Integer isDefault, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			productSkuService.executeUpdate(id, skuName, isDefault);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/deleteProductSku.do", method = RequestMethod.POST)
	public void deleteProductSku(Long id, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			productSkuService.executeDelete(id);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findRebateGridPage.do", method = RequestMethod.POST)
	public void findRebateGridPage(@RequestParam Map<String, Object> conditions, Long productId,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<RebateGrid> rebateGridPage = rebateGridService.findRebateGridPage(productId, pageNo,
						iDisplayLength, searchParams, mDataProp, sSortDir_0);

				BizData4Page<RebateGrid> bizData4Page = new BizData4Page<RebateGrid>();
				bizData4Page.setUserdata(conditions);
				if (rebateGridPage != null) {
					bizData4Page.setPage(rebateGridPage.getPageNo());
					bizData4Page.setPagesize(rebateGridPage.getPageSize());
					bizData4Page.setRecords(rebateGridPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<RebateGrid>(rebateGridPage.getEntities()));
					bizData4Page.setTotal(rebateGridPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateRebateGrid.do", method = RequestMethod.POST)
	public void updateRebateGrid(Long id, String col1, String col2, Integer sort, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			rebateGridService.executeUpdate(id, col1, col2, sort);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateProductRebateGrid.do", method = RequestMethod.POST)
	public void updateProductRebateGrid(Long productId, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			Product product = productService.findById(productId);
			if (null == product) {
				throw new ServiceException(StatusHouse.STATUS_PRODUCT_NOT_EXIST);
			}
			rebateGridService.executeAddUpdate(product);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}
}
